package com.qibo.baselib.utils;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;

import com.noober.background.drawable.DrawableCreator;

public class DensityUtil {
    /**
     * 不能初始化这个类
     */
    private DensityUtil() {
    }

    /**
     * dip转换px
     *
     * @param context 上下文
     * @param dpValue dip值
     * @return px值
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * sp转pd
     *
     * @param context 上下文
     * @param spValue sp值
     * @return px值
     */
    public static int sp2px(Context context, float spValue) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue,
                context.getResources().getDisplayMetrics());
    }

    /**
     * px转换dip
     *
     * @param context 上下文
     * @param pxValue px值
     * @return dip值
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }


    public static Drawable  setStrokeColorDrawable(Context context, String solidColor1 ,String strokeColor) {
        Drawable drawable = new DrawableCreator.Builder().setCornersRadius(DensityUtil.dip2px(context,3))
                .setRipple(true, Color.parseColor(solidColor1))
                .setSolidColor(Color.parseColor(solidColor1))
                .setStrokeColor(Color.parseColor(strokeColor))
                .setStrokeWidth(DensityUtil.dip2px(context,0.5f))
                .build();
        return drawable;
    }
}
